<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<h1>博为峰</h1>
		<div>学掌门</div>
		<button>ajax</button>
		<script type="text/javascript">
			/*
			  ajax:前后端交互的一种技术（页面局部刷新）
			*/

			const btn = document.querySelector("button");
			btn.addEventListener('click', function() {
				const xhr = new XMLHttpRequest();
				xhr.open('get', 'https://api.apiopen.top/api/sentences');
				xhr.send();
				xhr.onreadystatechange = function() {
					if (xhr.readyState == 4 && xhr.status == 200) {
						let r = xhr.responseText;
						const div = document.querySelector("div");
						div.innerHTML = r;
					}
				}
			})
		</script>
	</body>
</html>
